﻿using System;
using System.Windows.Markup;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace XtremeMvvm
{
    public abstract class MvvmResolver<T> : MarkupExtension
    {
        protected static readonly IUnityContainer container = 
        (
            MvvmHelper.IsInDesigner ? null : new UnityContainer().LoadConfiguration()
        );

        public static T ConcreteImplementation { get { return (container == null ? default(T) : container.Resolve<T>()); } }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return ConcreteImplementation;
        }
    }
}
